package com.wyt.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wyt.dao.BookTypeMapper;
import com.wyt.until.PageEntity;
import com.wyt.until.TableLayui;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author AAA
 * @date 2021/10/29 18:42("/tee
 */
@Controller
@RequestMapping("/bookType")
public class BookTypeController {
    @Autowired
    private BookTypeMapper bookTypeMapper;

    @ResponseBody
    @RequestMapping("/selectTeacher")
    public TableLayui selectBook(PageEntity pageEntity,@RequestParam Map map) {
        PageHelper.startPage(pageEntity.getPage(), pageEntity.getLimit());

        List<Map> list=bookTypeMapper.selectType(map);
        PageInfo pageInfo=new PageInfo(list);

        return new TableLayui(pageInfo.getTotal(),pageInfo.getList());
    }

    //根据id判断增加还是修改
    @ResponseBody
    @RequestMapping("/insertTeacher")
    public TableLayui insertBook1(@RequestParam Map map){
        System.out.println("1654654564654654");
        if (map.get("typeid")!=null&&map.get("typeid")!=""){
            bookTypeMapper.updateType(map);
            return new TableLayui(1,"失败",map);
        }
        bookTypeMapper.insertType(map);
        return new TableLayui(1,"失败",map);
    }

    @ResponseBody
    @RequestMapping(value = "/updateTeacher")
    public TableLayui updateBook(@RequestParam Map map){
        bookTypeMapper.updateType(map);
        return new TableLayui(1,"失败",map);
    }
  /*  @ResponseBody
    @RequestMapping("/selectid")
    public Map selectBookid(@RequestParam String bookid){
        return bookMapper.selectBookid(typeid);
    }*/

    //删除
    @ResponseBody
    @RequestMapping("/deleteTeacher")
    public TableLayui deleteBokk(@RequestParam Map map){
       bookTypeMapper.deleteType(map);
        return new TableLayui(1,"失败");
    }

//书籍类型查询
    @ResponseBody
    @RequestMapping("findAllbooktype")
    public TableLayui findAllbooktype() {
        List<Map> allBookTypes = bookTypeMapper.selectBookTypeAll();
        return new TableLayui(0, "成功", allBookTypes);
    }
}
